#!/bin/sh
# Convert all png images to eps in current or specified
# directory
case "$1" in
    "-h" | "--help" )
	echo "Usage:"
	echo "  png2eps will convert all png files of current directory to eps"
	echo "  png2eps a_directory will convert all png files of the specified directory to eps"
	echo ""
	;;
    * )
	CURRENT_DIR=""
	# save current directory and change to specified one
	if [ "$1" != "" ]
	    then
	    CURRENT_DIR= pwd
	    cd "$1"
	fi
	# process files
	for file in *.png
	  do
	  # only if we have some files
	  if [ "$file" != "*.png" ]
	      then
	      # get filename without extension
	      filename=`echo "$file" | sed s:.png::`
	      # process conversion if not empty
	      if [ "$filename" != "" ]
		  then
		  convert $filename'.png' $filename'.eps'
	      fi
	  fi
	done
	# restore current directory
	if [ "$CURRENT_DIR" != "" ]
	    then
	    cd "$CURRENT_DIR"
	fi
	;;
esac

exit 0	
